/*
 * @Description:
 * @Author: zhangwei
 * @Date: 2023-02-13 16:47:18
 * @LastEditTime: 2023-02-17 12:18:34
 * @LastEditors: zhangwei
 */

//json对象的深度克隆
export const deepClone = (origin: any) => {
  if (origin === undefined) {
    return undefined;
  }

  return JSON.parse(JSON.stringify(origin));
};

//生成随机ID
export const generateId = () => {
  return "xx4xxxyxxx".replace(/[xy]/g, function (c) {
    const r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
};

//判断对象、字符串、数组是否为空
export const isEmpty = (source: any[] | null | undefined | any) => {
  if (source == null || source === undefined) {
    return true;
  }

  if (source instanceof Array && source.length == 0) return true;

  //判断是否是字符串
  if (typeof source == "string" && source.trim().length == 0) return true;

  //判断是对象数组
  return false;
};

export default {
  deepClone,
  generateId,
  isEmpty,
};
